package org.point.dao.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.point.common.dao.impl.BaseDaoImpl;
import org.point.common.util.DoPage;
import org.point.dao.MemberDao;import org.point.domain.Member;
import org.springframework.stereotype.Repository;

/**
 * 
 * @ClassName: MemberDaoImpl  
 * @Description: TODO(会员单位数据实现类)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午3:41:14  
 *
 */
@Repository("memberDao")
public class MemberDaoImpl extends BaseDaoImpl<Member, Serializable> implements MemberDao {

	private static final String SQLID_SEARCHFORMEMBERPAGE = "search_For_Member_page";
	private static final String SQLID_SEARCHFORMEMBERCOUNT = "search_For_Users_count";
	private static final String SQLID_SEARCHMEMBER = "search_member";
	private static final String SQLID_UPDATEMEMBERPWD = "update_memberpwd";
	
	// 验证账号是否存在
	private static final String SQLID_ISACCOUNT = "is_account";
	// 验证账号密码是否正确
	private static final String SQLID_ISACCOUNTANDPWD = "is_accountandpwd";

	/**
	 * 利用反射，获取mapper.xml的namespace
	 * <p>Title: </p>  
	 * <p>Description: </p>
	 */
	public MemberDaoImpl() {
		namespace = super.getNamespace();
	}

	public List<Member> searchForMember(DoPage<Member> page) {
		List<Member> records = null;
		try {
			records = getSqlSession().selectList(namespace + SQLID_SEARCHFORMEMBERPAGE, page);
		} catch (Exception e) {
			throw new RuntimeException("查询数据总记录数错误！", e);
		}
		return records;
	}

	public Integer searchForMemberCount(DoPage<Member> page) {
		Integer result = 0;
		try {
			result = getSqlSession().selectOne(namespace + SQLID_SEARCHFORMEMBERCOUNT, page);
		} catch (Exception e) {
			throw new RuntimeException("查询数据总记录数错误！", e);
		}
		return result;
	}
	
	public List<Member> searchUserSignMap(Map<String, Object> map) {
		List<Member> members = getSqlSession().selectList(namespace + SQLID_SEARCHMEMBER);
		return members;
	}

	public Member isAccount(Map<String, Object> map) {
		Member record = null;
		try {
			record = getSqlSession().selectOne(namespace + SQLID_ISACCOUNT, map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return record;
	}

	public Member isAccountAndPwd(Map<String, Object> map) {
		Member record = null;
		try {
			record = getSqlSession().selectOne(namespace + SQLID_ISACCOUNTANDPWD, map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return record;
	}
	
	public Integer updateMemberPwd(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_UPDATEMEMBERPWD, map);
		} catch (Exception e){
			throw new RuntimeException("更新密码错误！", e);
		}
		return result;
	}
	
}
